package logic

import (
	"context"
	"fmt"
	"project/model/mysql"

	"project/projectrpc/internal/svc"
	"project/projectrpc/projectrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserAddLogic) UserAdd(in *projectrpc.UserAddRequest) (*projectrpc.UserAddResponse, error) {
	// todo: add your logic here and delete this line

	myself := mysql.Myself{
		Username: in.Username,
		Tel:      in.Tel,
		Email:    in.Email,
		Price:    float64(in.Price),
	}
	err := mysql.DB.Create(&myself).Error
	if err != nil {
		return nil, fmt.Errorf("添加失败")
	}

	return &projectrpc.UserAddResponse{Id: int64(myself.ID)}, nil
}
